package com.example.talkheart.adapter


import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.talkheart.MyApplication
import com.example.talkheart.R
import com.example.talkheart.entity.TeacherBean

open class AccountAdapter : RecyclerView.Adapter<AccountAdapter.AccountViewHolder>() {
    var dataList = ArrayList<String>()
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): AccountViewHolder {
        val view = LayoutInflater.from(MyApplication.context).inflate(R.layout.account_item,parent,false)
        return AccountViewHolder(view)
    }

    override fun onBindViewHolder(holder: AccountViewHolder, position: Int) {
        holder.accountText.text = dataList.get(position)
    }

    open fun addItem(text : String){
        dataList.add(text)
        notifyItemChanged(dataList.size-1)
    }

    override fun getItemCount(): Int {
        return if(dataList.isEmpty())
            0
        else
            dataList.size
    }

    class AccountViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val accountText : TextView = itemView.findViewById(R.id.accountText)
    }
}